﻿using GlennQuigmire.API.Application.Commands;
using GlennQuigmire.API.Application.GDtos;
using IMES.Common.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace GlennQuigmire.API.Controllers
{
    /// <summary>
    /// 物料信息控制器--API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialsController : ControllerBase
    {
        private readonly IMediator mediator;

        public MaterialsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加物料信息
        /// </summary>
        /// <param name="cmd">添加物料信息请求对象</param>
        /// <returns>添加物料信息响应对象</returns>
        [HttpPost]
        public Task<Result> MaterilCreate(MaterialCreateCommand cmd)
        {
            return mediator.Send(cmd);
        }

        /// <summary>
        /// 物料信息查询显示
        /// </summary>
        /// <param name="cmd">物料信息查询显示请求对象</param>
        /// <returns>物料信息查询显示响应对象</returns>
        [HttpGet]
        public async Task<ResultPage<MaterialListDto>> MaterilSearch([FromQuery] MaterialSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取物料产品
        /// </summary>
        /// <param name="cmd">获取物料产品请求对象</param>
        /// <returns>返回物料产品响应对象</returns>
        [HttpGet]
        public async Task<ResultT<MaterialParentIdsDto>> MaterialParentIdSearch([FromQuery]MaterialParentIdSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 获取物料父级Id
        /// </summary>
        /// <param name="cmd">获取物料父级Id请求对象</param>
        /// <returns>返回父级物料id响应对象</returns>
        [HttpPost]
        public async Task<ResultT<MaterialTreeDto>> MaterialProductTreeSearch(MaterialSearchTreeCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 反添商品信息
        /// </summary>
        /// <param name="cmd">反添商品信息请求参数</param>
        /// <returns>反添的商品信息数据</returns>
        [HttpPost]
        public Task<Result> ProductDetail(ProductDetailCommand cmd)
        {
            return mediator.Send(cmd);
        }


    }
}
